{extend name="public/base" /}{block name='body'}
<div class="layui-container">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md8">
            <div class="fly-panel sw-last-box">
                <div class="fly-panel-title fly-filter">
                    <a>最近更新</a>
                </div>
                <ul class="fly-list" id="sw-res-last-list">

                </ul>
            </div>

            <div class="fly-panel sw-rescats-box">

                <div class="fly-panel-title fly-filter" id='sw-res-searchs'>
                    <a target="{:url('index/maxTops')}" class="layui-this">最精</a>
                    <span class="fly-mid"></span>
                    <a target="{:url('index/maxPageviews')}">最热</a>
                    <span class="fly-mid"></span>
                    <a target="{:url('index/maxPrice')}">最贵</a>
                    <span class="fly-mid"></span>
                    <a target="{:url('index/maxDownloads')}">下载最多</a>
                    <span class="fly-filter-right layui-hide-xs">
                    </span>
                </div>

                <ul class="fly-list" id="sw-res-searchs-list">

                </ul>

            </div>
        </div>
        <div class="layui-col-md4">
            <!--签到-->
            <div class="fly-panel fly-signin">
                <div class="fly-panel-title">
                    签到
                    <i class="fly-mid"></i>
                    <a href="javascript:;" class="fly-link" id="LAY_signinHelp">说明</a>
                    <i class="fly-mid"></i>
                    <span class="fly-signin-days">已签到<cite>{$Think.session.ureports|default=0}</cite>天</span>
                </div>
                <div class="fly-panel-main fly-signin-main">
                    <!--签到-->
                    <button class="layui-btn layui-btn-danger" id="sw-report">今日签到</button>
                    <span>可获得<cite>1</cite>金币</span>

                    <!-- 已签到状态 -->
                    <!--
                    <button class="layui-btn layui-btn-disabled">今日已签到</button>
                    <span>获得了<cite>20</cite>飞吻</span>
                    -->
                </div>
            </div>

            <!--资源分类-->
            <div class="fly-panel fly-rank fly-rank-reply">
                <h3 class="fly-panel-title">资源分类</h3>
                <dl>
                    {volist name='cats' id='cat'}
                    <dd>
                        <a href="{:url('base/search')}">
                            <img id="sw-cat-icon" src="__PUBLIC__/{$cat['Icon']}">
                            <i>{$cat.Name}</i>
                        </a>
                    </dd>
                    {/volist}
                    <dd>
                        <a href="{:url('base/search')}">
                            <img src="__IMG__/allcategoryIcon.png"> <i>所有分类</i>
                        </a>
                    </dd>
                </dl>
            </div>

            <!--评论榜首-->
            <div class="fly-panel fly-rank fly-rank-reply" id="LAY_replyRank">
                <h3 class="fly-panel-title">最近访客</h3>
                <dl>
                    {volist name='lu' id='v'}
                    <dd>
                        <a href="{:url('user/userDetail')}?guid={$v['PK_UserGuid']}">
                            <img src="__PUBLIC__/{$v.Cover}"><cite>{$v.recomment|comment_array_to_count}评论</cite><i>{$v.Name}</i>
                        </a>
                    </dd>
                    {/volist}
                </dl>
            </div>

            <!--热门-->


            <!--友情链接-->
            <div class="fly-panel fly-link">
                <h3 class="fly-panel-title">友情链接</h3>
                <dl class="fly-panel-main">
                    <dd><a href="http://www.layui.com/" target="_blank">layui</a>
                    <dd>
                    <dd><a href="http://layim.layui.com/" target="_blank">WebIM</a>
                    <dd>
                    <dd><a href="http://layer.layui.com/" target="_blank">layer</a>
                    <dd>
                    <dd><a href="http://www.layui.com/laydate/" target="_blank">layDate</a>
                    <dd>
                    <dd>
                        <a href="mailto:xianxin@layui-inc.com?subject=%E7%94%B3%E8%AF%B7Fly%E7%A4%BE%E5%8C%BA%E5%8F%8B%E9%93%BE"
                           class="fly-link">申请友链</a>
                    <dd>
                </dl>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['jquery', 'layer'], function () {
        let $ = layui.jquery;
        let layer = layui.layer;
        let emptyTpl = `{include file='tpl/searchEmpty'}`;

        //签到
        $('#sw-report').on('click', function () {
            $.get("{:url('user/reports')}", function (res) {
                if (res.errno === 0) return layer.msg('签到成功');
                else return layer.msg(res.errmsg);
            });
        });

        //模板处理
        function dataToHtml(resAttr) {
            return resTpl = `{include file="tpl/resItems"}`;
        }

        //获取数据
        $('#sw-res-searchs a').click(function () {
            //css切换
            $('#sw-res-searchs a').removeClass('layui-this')
            $(this).addClass('layui-this');
            let api = $(this).attr('target');
            let loadCat = layer.load(2);
            doGet(api,'sw-res-searchs-list',loadCat)
        });

        /**
         * 发送请求
         */
        function doGet(api, select, loadid) {
            $.get(api, function (res) {
                layer.close(loadid);
                if (res.errno === 3) {
                    return $('#' + select).html(emptyTpl);
                }
                if(res.errno===0){
                    let parsed = '';
                    $.each(res.data, function (index, obj) {
                        parsed += dataToHtml(obj);
                    });
                    parsed += `{include file="tpl/moreRes"}`;
                    return $('#' + select).html(parsed);
                }

            });
        }

        /**
         * 最新
         */
        var last=layer.load();
        doGet("{:url('index/lastResApi')}",'sw-res-searchs-list',last);

        /**
         * 最高
         */
        var top=layer.load();
        doGet("{:url('index/maxTops')}",'sw-res-last-list',top);

    });
</script>{/block}